-- A simple scene with some miscellaneous geometry.

mat1 = gr.material({0.7, 1.0, 0.7}, {0.5, 0.7, 0.5}, 25)
mat2 = gr.material({0.5, 0.5, 0.5}, {0.5, 0.7, 0.5}, 25)
mat3 = gr.material({1.0, 0.6, 0.1}, {0.5, 0.7, 0.5}, 25)
mat4 = gr.material({0.7, 0.6, 1.0}, {0.5, 0.4, 0.8}, 25)
mat5 = gr.material({0.5, 0, 0}, {0.5, 0.4, 0.8}, 25)
mat6 = gr.material({0.2,0.4,0.6}, {0.3,0.3,0.3},25)

scene_root = gr.node('root')
scene_root:rotate('x',23)

cube1 = gr.nh_box('c1',{0,0,0},30)
cube1:set_material(mat1)
cube1:scale(2,1,1)

cube2 = gr.nh_box('c2',{15,0,-7.5},30)
cube2:set_material(mat1)
cube2:scale(1,1,2)

cube3 = gr.nh_box('c3',{15,-7.5,0},30)
cube3:set_material(mat1)
cube3:scale(1,2,1)

csg1 = gr.csg('csg1',1,cube1,cube2)
csg2 = gr.csg('csg2',1,csg1,cube3)

cube4 = gr.nh_box('c3',{10,-5,-5},40)
cube4:set_material(mat1)
csg3 = gr.csg('csg3',3,cube4,csg2)

sphere1 = gr.nh_sphere('sphere1',{30,15,15},15)
sphere1:set_material(mat6)

csg4 = gr.csg('csg3',1,csg3,sphere1)
csg4:scale(2,2,2)

csg4:translate(20,-35,0)
csg4:rotate('x',-10)
scene_root:add_child(csg4)
--######################################### C - (c+c+c) + s 

cy1 = gr.cylinder('cy1',40,80)
cy1:set_material(mat3)

cy2 = gr.cylinder('cy2',40,80)
cy2:set_material(mat1)
cy2:rotate('z',90)
cy2:translate(40,-40,0)

cy3 = gr.cylinder('cy3',40,80)
cy3:set_material(mat2)
cy3:rotate('x',90)
cy3:translate(0,-40,-40)

csg_cy1 = gr.csg('csg_cy1',2,cy1,cy2)
csg_cy2 = gr.csg('csg_cy2',2,csg_cy1,cy3)
csg_cy2:rotate('x',35)
csg_cy2:translate(-70,80,0)
scene_root:add_child(csg_cy2)

--######################################### cy^cy^cy

cone1 = gr.cone('co1',40,150)
cone1:set_material(mat4)
cylinder1 = gr.cylinder('cyl1',30,150)
cylinder1:set_material(mat1)

csg_cone1 = gr.csg('csg_cone1',2,cone1,cylinder1)

cylinder2 = gr.cylinder('cyl2',30,30)
cylinder2:set_material(mat2)
cylinder2:translate(0,60,0)

csg_cone2 = gr.csg('csg_cone2',3,csg_cone1,cylinder2)
csg_cone2:rotate('z',-30)
scene_root:add_child(csg_cone2)
--######################################## cone ^ cylinder - cylinder

torus1 = gr.torus('torus1',20,40)
torus1:set_material(mat3)

sphere2 = gr.nh_sphere('sphere2',{-50,0,0},40)
sphere2:set_material(mat4)

csg_torus1 = gr.csg('csg_torus1',3,torus1,sphere2)
csg_torus1:rotate('y',50)
csg_torus1:translate(-70,-30,0)
scene_root:add_child(csg_torus1)
--######################################## torus - sphere
white_light = gr.light(1,0,{0.0, -100.0, 400.0}, {0.9, 0.9, 0.9}, {1, 0, 0})

gr.render(scene_root, 'csg.png', 500, 500,
	  {0, 0, 400}, {0, 0, -1}, {0, 1, 0}, 50,
	  {0.3, 0.3, 0.3}, {white_light},1,0,0,0,0,0)
